2020-2021 Sunseeker Telemetry and Lighting System
rtc_b_ex1_calendermode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 #include "driverlib.h"
66 
67 volatile Calendar newTime;
68 
69 void main (void)
70 {
71  Calendar currentTime;
72 
73  WDT_A_hold(WDT_A_BASE);
74 
75  //Set P1.0 to output direction
76  GPIO_setAsOutputPin(
77  GPIO_PORT_P1,
78  GPIO_PIN0
79  );
80 
81  /*
82  * Select Port J
83  * Set Pin 4, 5 to input Primary Module Function, LFXT.
84  */
85  GPIO_setAsPeripheralModuleFunctionInputPin(
86  GPIO_PORT_PJ,
87  GPIO_PIN4 + GPIO_PIN5,
88  GPIO_PRIMARY_MODULE_FUNCTION
89  );
90 
91  /*
92  * Disable the GPIO power-on default high-impedance mode to activate
93  * previously configured port settings
94  */
95  PMM_unlockLPM5();
96 
97  //Initialize LFXT1
98  CS_turnOnLFXT(
99  CS_LFXT_DRIVE_3
100  );
101 
102  //Setup Current Time for Calendar
103  currentTime.Seconds = 0x00;
104  currentTime.Minutes = 0x26;
105  currentTime.Hours = 0x13;
106  currentTime.DayOfWeek = 0x03;
107  currentTime.DayOfMonth = 0x20;
108  currentTime.Month = 0x07;
109  currentTime.Year = 0x2011;
110 
111  //Initialize Calendar Mode of RTC
112  /*
113  * Base Address of the RTC_B
114  * Pass in current time, intialized above
115  * Use BCD as Calendar Register Format
116  */
117  RTC_B_initCalendar(RTC_B_BASE,
118  &currentTime,
119  RTC_B_FORMAT_BCD);
120 
121  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
122  //Note: Does not specify day of the week.
123  RTC_B_configureCalendarAlarmParam param = {0};
124  param.minutesAlarm = 0x00;
125  param.hoursAlarm = 0x17;
126  param.dayOfWeekAlarm = RTC_B_ALARMCONDITION_OFF;
127  param.dayOfMonthAlarm = 0x05;
128  RTC_B_configureCalendarAlarm(RTC_B_BASE, &param);
129 
130  //Specify an interrupt to assert every minute
131  RTC_B_setCalendarEvent(RTC_B_BASE,
132  RTC_B_CALENDAREVENT_MINUTECHANGE);
133 
134  RTC_B_clearInterrupt(RTC_B_BASE,
135  RTC_B_CLOCK_READ_READY_INTERRUPT +
136  RTC_B_TIME_EVENT_INTERRUPT +
137  RTC_B_CLOCK_ALARM_INTERRUPT
138  );
139  //Enable interrupt for RTC Ready Status, which asserts when the RTC
140  //Calendar registers are ready to read.
141  //Also, enable interrupts for the Calendar alarm and Calendar event.
142  RTC_B_enableInterrupt(RTC_B_BASE,
143  RTC_B_CLOCK_READ_READY_INTERRUPT +
144  RTC_B_TIME_EVENT_INTERRUPT +
145  RTC_B_CLOCK_ALARM_INTERRUPT
146  );
147 
148  //Start RTC Clock
149  RTC_B_startClock(RTC_B_BASE);
150 
151  //Enter LPM3 mode with interrupts enabled
152  __bis_SR_register(LPM0_bits + GIE);
153  __no_operation();
154 }
155 
156 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
157 #pragma vector=RTC_VECTOR
158 __interrupt
159 #elif defined(__GNUC__)
160 __attribute__((interrupt(RTC_VECTOR)))
161 #endif
162 void RTC_B_ISR (void)
163 {
164  switch (__even_in_range(RTCIV,16)){
165  case 0: break; //No interrupts
166  case 2: //RTCRDYIFG
167  //Toggle P1.0 every second
168  GPIO_toggleOutputOnPin(
169  GPIO_PORT_P1,
170  GPIO_PIN0);
171  break;
172  case 4: //RTCEVIFG
173  //Interrupts every minute
174  __no_operation();
175 
176  //Read out New Time a Minute Later BREAKPOINT HERE
177  newTime = RTC_B_getCalendarTime(RTC_B_BASE);
178  break;
179  case 6: //RTCAIFG
180  //Interrupts 5:00pm on 5th day of week
181  __no_operation();
182  break;
183  case 8: break; //RT0PSIFG
184  case 10: break; //RT1PSIFG
185  case 12: break; //Reserved
186  case 14: break; //Reserved
187  case 16: break; //Reserved
188  default: break;
189  }
190 }
191 
MPU_initThreeSegmentsParam param
void main(void)
void RTC_B_ISR(void)
volatile Calendar newTime
__no_operation()